﻿using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Linq.Expressions;
using System.ComponentModel;
using System;

namespace Money.Entities
{
    [Table(Name = "dbo.Accounts")]
    public partial class Account : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _AccountId;

        private System.Nullable<int> _UserId;

        private string _DisplayName;

        private System.Nullable<int> _CurrencyType;

        private System.Nullable<int> _AccountType;

        private System.Nullable<decimal> _InitBalance;

        private string _Description;

        private string _ContactName;

        private string _ContactPhone;

        private System.Nullable<System.DateTime> _CreationDate;

        private EntitySet<MemorizedTransaction> _MemorizedTransactions;

        private EntitySet<Transaction> _Transactions;

        private EntityRef<User> _User;

        private EntityRef<AccountType> _AccountType1;

        private EntityRef<Currency> _Currency;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnAccountIdChanging(int value);
        partial void OnAccountIdChanged();
        partial void OnUserIdChanging(System.Nullable<int> value);
        partial void OnUserIdChanged();
        partial void OnDisplayNameChanging(string value);
        partial void OnDisplayNameChanged();
        partial void OnCurrencyTypeChanging(System.Nullable<int> value);
        partial void OnCurrencyTypeChanged();
        partial void OnAccountTypeChanging(System.Nullable<int> value);
        partial void OnAccountTypeChanged();
        partial void OnInitBalanceChanging(System.Nullable<decimal> value);
        partial void OnInitBalanceChanged();
        partial void OnDescriptionChanging(string value);
        partial void OnDescriptionChanged();
        partial void OnContactNameChanging(string value);
        partial void OnContactNameChanged();
        partial void OnContactPhoneChanging(string value);
        partial void OnContactPhoneChanged();
        partial void OnCreationDateChanging(System.Nullable<System.DateTime> value);
        partial void OnCreationDateChanged();
        #endregion

        public Account()
        {
            this._MemorizedTransactions = new EntitySet<MemorizedTransaction>(new Action<MemorizedTransaction>(this.attach_MemorizedTransactions), new Action<MemorizedTransaction>(this.detach_MemorizedTransactions));
            this._Transactions = new EntitySet<Transaction>(new Action<Transaction>(this.attach_Transactions), new Action<Transaction>(this.detach_Transactions));
            this._User = default(EntityRef<User>);
            this._AccountType1 = default(EntityRef<AccountType>);
            this._Currency = default(EntityRef<Currency>);
            OnCreated();
        }

        [Column(Storage = "_AccountId", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int AccountId
        {
            get
            {
                return this._AccountId;
            }
            set
            {
                if ((this._AccountId != value))
                {
                    this.OnAccountIdChanging(value);
                    this.SendPropertyChanging();
                    this._AccountId = value;
                    this.SendPropertyChanged("AccountId");
                    this.OnAccountIdChanged();
                }
            }
        }

        [Column(Storage = "_UserId", DbType = "Int")]
        public System.Nullable<int> UserId
        {
            get
            {
                return this._UserId;
            }
            set
            {
                if ((this._UserId != value))
                {
                    if (this._User.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnUserIdChanging(value);
                    this.SendPropertyChanging();
                    this._UserId = value;
                    this.SendPropertyChanged("UserId");
                    this.OnUserIdChanged();
                }
            }
        }

        [Column(Storage = "_DisplayName", DbType = "NVarChar(50)")]
        public string DisplayName
        {
            get
            {
                return this._DisplayName;
            }
            set
            {
                if ((this._DisplayName != value))
                {
                    this.OnDisplayNameChanging(value);
                    this.SendPropertyChanging();
                    this._DisplayName = value;
                    this.SendPropertyChanged("DisplayName");
                    this.OnDisplayNameChanged();
                }
            }
        }

        [Column(Storage = "_CurrencyType", DbType = "Int")]
        public System.Nullable<int> CurrencyType
        {
            get
            {
                return this._CurrencyType;
            }
            set
            {
                if ((this._CurrencyType != value))
                {
                    if (this._Currency.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnCurrencyTypeChanging(value);
                    this.SendPropertyChanging();
                    this._CurrencyType = value;
                    this.SendPropertyChanged("CurrencyType");
                    this.OnCurrencyTypeChanged();
                }
            }
        }

        [Column(Storage = "_AccountType", DbType = "Int")]
        public System.Nullable<int> AccountType
        {
            get
            {
                return this._AccountType;
            }
            set
            {
                if ((this._AccountType != value))
                {
                    if (this._AccountType1.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnAccountTypeChanging(value);
                    this.SendPropertyChanging();
                    this._AccountType = value;
                    this.SendPropertyChanged("AccountType");
                    this.OnAccountTypeChanged();
                }
            }
        }

        [Column(Storage = "_InitBalance", DbType = "Money")]
        public System.Nullable<decimal> InitBalance
        {
            get
            {
                return this._InitBalance;
            }
            set
            {
                if ((this._InitBalance != value))
                {
                    this.OnInitBalanceChanging(value);
                    this.SendPropertyChanging();
                    this._InitBalance = value;
                    this.SendPropertyChanged("InitBalance");
                    this.OnInitBalanceChanged();
                }
            }
        }

        [Column(Storage = "_Description", DbType = "NVarChar(100)")]
        public string Description
        {
            get
            {
                return this._Description;
            }
            set
            {
                if ((this._Description != value))
                {
                    this.OnDescriptionChanging(value);
                    this.SendPropertyChanging();
                    this._Description = value;
                    this.SendPropertyChanged("Description");
                    this.OnDescriptionChanged();
                }
            }
        }

        [Column(Storage = "_ContactName", DbType = "NVarChar(50)")]
        public string ContactName
        {
            get
            {
                return this._ContactName;
            }
            set
            {
                if ((this._ContactName != value))
                {
                    this.OnContactNameChanging(value);
                    this.SendPropertyChanging();
                    this._ContactName = value;
                    this.SendPropertyChanged("ContactName");
                    this.OnContactNameChanged();
                }
            }
        }

        [Column(Storage = "_ContactPhone", DbType = "NVarChar(50)")]
        public string ContactPhone
        {
            get
            {
                return this._ContactPhone;
            }
            set
            {
                if ((this._ContactPhone != value))
                {
                    this.OnContactPhoneChanging(value);
                    this.SendPropertyChanging();
                    this._ContactPhone = value;
                    this.SendPropertyChanged("ContactPhone");
                    this.OnContactPhoneChanged();
                }
            }
        }

        [Column(Storage = "_CreationDate", DbType = "DateTime")]
        public System.Nullable<System.DateTime> CreationDate
        {
            get
            {
                return this._CreationDate;
            }
            set
            {
                if ((this._CreationDate != value))
                {
                    this.OnCreationDateChanging(value);
                    this.SendPropertyChanging();
                    this._CreationDate = value;
                    this.SendPropertyChanged("CreationDate");
                    this.OnCreationDateChanged();
                }
            }
        }

        [Association(Name = "Account_MemorizedTransaction", Storage = "_MemorizedTransactions", ThisKey = "AccountId", OtherKey = "AccountId")]
        public EntitySet<MemorizedTransaction> MemorizedTransactions
        {
            get
            {
                return this._MemorizedTransactions;
            }
            set
            {
                this._MemorizedTransactions.Assign(value);
            }
        }

        [Association(Name = "Account_Transaction", Storage = "_Transactions", ThisKey = "AccountId", OtherKey = "AccountId")]
        public EntitySet<Transaction> Transactions
        {
            get
            {
                return this._Transactions;
            }
            set
            {
                this._Transactions.Assign(value);
            }
        }

        [Association(Name = "User_Account", Storage = "_User", ThisKey = "UserId", OtherKey = "UserId", IsForeignKey = true)]
        public User User
        {
            get
            {
                return this._User.Entity;
            }
            set
            {
                User previousValue = this._User.Entity;
                if (((previousValue != value)
                            || (this._User.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._User.Entity = null;
                        previousValue.Accounts.Remove(this);
                    }
                    this._User.Entity = value;
                    if ((value != null))
                    {
                        value.Accounts.Add(this);
                        this._UserId = value.UserId;
                    }
                    else
                    {
                        this._UserId = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("User");
                }
            }
        }

        [Association(Name = "AccountType_Account", Storage = "_AccountType1", ThisKey = "AccountType", OtherKey = "Id", IsForeignKey = true)]
        public AccountType AccountType1
        {
            get
            {
                return this._AccountType1.Entity;
            }
            set
            {
                AccountType previousValue = this._AccountType1.Entity;
                if (((previousValue != value)
                            || (this._AccountType1.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._AccountType1.Entity = null;
                        previousValue.Accounts.Remove(this);
                    }
                    this._AccountType1.Entity = value;
                    if ((value != null))
                    {
                        value.Accounts.Add(this);
                        this._AccountType = value.Id;
                    }
                    else
                    {
                        this._AccountType = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("AccountType1");
                }
            }
        }

        [Association(Name = "Currency_Account", Storage = "_Currency", ThisKey = "CurrencyType", OtherKey = "Id", IsForeignKey = true)]
        public Currency Currency
        {
            get
            {
                return this._Currency.Entity;
            }
            set
            {
                Currency previousValue = this._Currency.Entity;
                if (((previousValue != value)
                            || (this._Currency.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Currency.Entity = null;
                        previousValue.Accounts.Remove(this);
                    }
                    this._Currency.Entity = value;
                    if ((value != null))
                    {
                        value.Accounts.Add(this);
                        this._CurrencyType = value.Id;
                    }
                    else
                    {
                        this._CurrencyType = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("Currency");
                }
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void attach_MemorizedTransactions(MemorizedTransaction entity)
        {
            this.SendPropertyChanging();
            entity.Account = this;
        }

        private void detach_MemorizedTransactions(MemorizedTransaction entity)
        {
            this.SendPropertyChanging();
            entity.Account = null;
        }

        private void attach_Transactions(Transaction entity)
        {
            this.SendPropertyChanging();
            entity.Account = this;
        }

        private void detach_Transactions(Transaction entity)
        {
            this.SendPropertyChanging();
            entity.Account = null;
        }
    }

    [Table(Name = "dbo.Users")]
    public partial class User : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _UserId;

        private string _Username;

        private string _Password;

        private string _Email;

        private string _FirstName;

        private string _LastName;

        private EntitySet<Account> _Accounts;

        private EntitySet<UserInRole> _UserInRoles;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnUserIdChanging(int value);
        partial void OnUserIdChanged();
        partial void OnUsernameChanging(string value);
        partial void OnUsernameChanged();
        partial void OnPasswordChanging(string value);
        partial void OnPasswordChanged();
        partial void OnEmailChanging(string value);
        partial void OnEmailChanged();
        partial void OnFirstNameChanging(string value);
        partial void OnFirstNameChanged();
        partial void OnLastNameChanging(string value);
        partial void OnLastNameChanged();
        #endregion

        public User()
        {
            this._Accounts = new EntitySet<Account>(new Action<Account>(this.attach_Accounts), new Action<Account>(this.detach_Accounts));
            this._UserInRoles = new EntitySet<UserInRole>(new Action<UserInRole>(this.attach_UserInRoles), new Action<UserInRole>(this.detach_UserInRoles));
            OnCreated();
        }

        [Column(Storage = "_UserId", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int UserId
        {
            get
            {
                return this._UserId;
            }
            set
            {
                if ((this._UserId != value))
                {
                    this.OnUserIdChanging(value);
                    this.SendPropertyChanging();
                    this._UserId = value;
                    this.SendPropertyChanged("UserId");
                    this.OnUserIdChanged();
                }
            }
        }

        [Column(Storage = "_Username", DbType = "NVarChar(100)")]
        public string Username
        {
            get
            {
                return this._Username;
            }
            set
            {
                if ((this._Username != value))
                {
                    this.OnUsernameChanging(value);
                    this.SendPropertyChanging();
                    this._Username = value;
                    this.SendPropertyChanged("Username");
                    this.OnUsernameChanged();
                }
            }
        }

        [Column(Storage = "_Password", DbType = "NVarChar(100)")]
        public string Password
        {
            get
            {
                return this._Password;
            }
            set
            {
                if ((this._Password != value))
                {
                    this.OnPasswordChanging(value);
                    this.SendPropertyChanging();
                    this._Password = value;
                    this.SendPropertyChanged("Password");
                    this.OnPasswordChanged();
                }
            }
        }

        [Column(Storage = "_Email", DbType = "NVarChar(100)")]
        public string Email
        {
            get
            {
                return this._Email;
            }
            set
            {
                if ((this._Email != value))
                {
                    this.OnEmailChanging(value);
                    this.SendPropertyChanging();
                    this._Email = value;
                    this.SendPropertyChanged("Email");
                    this.OnEmailChanged();
                }
            }
        }

        [Column(Storage = "_FirstName", DbType = "NVarChar(100)")]
        public string FirstName
        {
            get
            {
                return this._FirstName;
            }
            set
            {
                if ((this._FirstName != value))
                {
                    this.OnFirstNameChanging(value);
                    this.SendPropertyChanging();
                    this._FirstName = value;
                    this.SendPropertyChanged("FirstName");
                    this.OnFirstNameChanged();
                }
            }
        }

        [Column(Storage = "_LastName", DbType = "NVarChar(100)")]
        public string LastName
        {
            get
            {
                return this._LastName;
            }
            set
            {
                if ((this._LastName != value))
                {
                    this.OnLastNameChanging(value);
                    this.SendPropertyChanging();
                    this._LastName = value;
                    this.SendPropertyChanged("LastName");
                    this.OnLastNameChanged();
                }
            }
        }

        [Association(Name = "User_Account", Storage = "_Accounts", ThisKey = "UserId", OtherKey = "UserId")]
        public EntitySet<Account> Accounts
        {
            get
            {
                return this._Accounts;
            }
            set
            {
                this._Accounts.Assign(value);
            }
        }

        [Association(Name = "User_UserInRole", Storage = "_UserInRoles", ThisKey = "UserId", OtherKey = "UserId")]
        public EntitySet<UserInRole> UserInRoles
        {
            get
            {
                return this._UserInRoles;
            }
            set
            {
                this._UserInRoles.Assign(value);
            }
        }

        public List<Role> Roles
        {
            get
            {
                var query = from uir in this.UserInRoles
                            where uir.UserId == this.UserId
                            select uir.Role;
                return query.ToList<Role>();
            }
            set
            {
                this.UserInRoles.Clear();
                foreach (Role item in value)
                {
                    UserInRole uir = new UserInRole();
                    uir.UserId = this.UserId;
                    uir.RoleId = item.RoleId;
                    this.UserInRoles.Add(uir);
                }
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void attach_Accounts(Account entity)
        {
            this.SendPropertyChanging();
            entity.User = this;
        }

        private void detach_Accounts(Account entity)
        {
            this.SendPropertyChanging();
            entity.User = null;
        }

        private void attach_UserInRoles(UserInRole entity)
        {
            this.SendPropertyChanging();
            entity.User = this;
        }

        private void detach_UserInRoles(UserInRole entity)
        {
            this.SendPropertyChanging();
            entity.User = null;
        }
    }

    [Table(Name = "dbo.AccountTypes")]
    public partial class AccountType : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _Id;

        private string _Name;

        private EntitySet<Account> _Accounts;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnIdChanging(int value);
        partial void OnIdChanged();
        partial void OnNameChanging(string value);
        partial void OnNameChanged();
        #endregion

        public AccountType()
        {
            this._Accounts = new EntitySet<Account>(new Action<Account>(this.attach_Accounts), new Action<Account>(this.detach_Accounts));
            OnCreated();
        }

        [Column(Storage = "_Id", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int Id
        {
            get
            {
                return this._Id;
            }
            set
            {
                if ((this._Id != value))
                {
                    this.OnIdChanging(value);
                    this.SendPropertyChanging();
                    this._Id = value;
                    this.SendPropertyChanged("Id");
                    this.OnIdChanged();
                }
            }
        }

        [Column(Storage = "_Name", DbType = "NVarChar(50)")]
        public string Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                if ((this._Name != value))
                {
                    this.OnNameChanging(value);
                    this.SendPropertyChanging();
                    this._Name = value;
                    this.SendPropertyChanged("Name");
                    this.OnNameChanged();
                }
            }
        }

        [Association(Name = "AccountType_Account", Storage = "_Accounts", ThisKey = "Id", OtherKey = "AccountType")]
        public EntitySet<Account> Accounts
        {
            get
            {
                return this._Accounts;
            }
            set
            {
                this._Accounts.Assign(value);
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void attach_Accounts(Account entity)
        {
            this.SendPropertyChanging();
            entity.AccountType1 = this;
        }

        private void detach_Accounts(Account entity)
        {
            this.SendPropertyChanging();
            entity.AccountType1 = null;
        }
    }

    [Table(Name = "dbo.Categories")]
    public partial class Category : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _Id;

        private string _Name;

        private System.Nullable<int> _ParentId;

        private EntitySet<Category> _Categories;

        private EntitySet<MemorizedTransaction> _MemorizedTransactions;

        private EntitySet<Transaction> _Transactions;

        private EntityRef<Category> _Category1;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnIdChanging(int value);
        partial void OnIdChanged();
        partial void OnNameChanging(string value);
        partial void OnNameChanged();
        partial void OnParentIdChanging(System.Nullable<int> value);
        partial void OnParentIdChanged();
        #endregion

        public Category()
        {
            this._Categories = new EntitySet<Category>(new Action<Category>(this.attach_Categories), new Action<Category>(this.detach_Categories));
            this._MemorizedTransactions = new EntitySet<MemorizedTransaction>(new Action<MemorizedTransaction>(this.attach_MemorizedTransactions), new Action<MemorizedTransaction>(this.detach_MemorizedTransactions));
            this._Transactions = new EntitySet<Transaction>(new Action<Transaction>(this.attach_Transactions), new Action<Transaction>(this.detach_Transactions));
            this._Category1 = default(EntityRef<Category>);
            OnCreated();
        }

        [Column(Storage = "_Id", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int Id
        {
            get
            {
                return this._Id;
            }
            set
            {
                if ((this._Id != value))
                {
                    this.OnIdChanging(value);
                    this.SendPropertyChanging();
                    this._Id = value;
                    this.SendPropertyChanged("Id");
                    this.OnIdChanged();
                }
            }
        }

        [Column(Storage = "_Name", DbType = "NVarChar(50)")]
        public string Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                if ((this._Name != value))
                {
                    this.OnNameChanging(value);
                    this.SendPropertyChanging();
                    this._Name = value;
                    this.SendPropertyChanged("Name");
                    this.OnNameChanged();
                }
            }
        }

        [Column(Storage = "_ParentId", DbType = "Int")]
        public System.Nullable<int> ParentId
        {
            get
            {
                return this._ParentId;
            }
            set
            {
                if ((this._ParentId != value))
                {
                    if (this._Category1.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnParentIdChanging(value);
                    this.SendPropertyChanging();
                    this._ParentId = value;
                    this.SendPropertyChanged("ParentId");
                    this.OnParentIdChanged();
                }
            }
        }

        [Association(Name = "Category_Category", Storage = "_Categories", ThisKey = "Id", OtherKey = "ParentId")]
        public EntitySet<Category> Categories
        {
            get
            {
                return this._Categories;
            }
            set
            {
                this._Categories.Assign(value);
            }
        }

        [Association(Name = "Category_MemorizedTransaction", Storage = "_MemorizedTransactions", ThisKey = "Id", OtherKey = "CategoryId")]
        public EntitySet<MemorizedTransaction> MemorizedTransactions
        {
            get
            {
                return this._MemorizedTransactions;
            }
            set
            {
                this._MemorizedTransactions.Assign(value);
            }
        }

        [Association(Name = "Category_Transaction", Storage = "_Transactions", ThisKey = "Id", OtherKey = "CategoryId")]
        public EntitySet<Transaction> Transactions
        {
            get
            {
                return this._Transactions;
            }
            set
            {
                this._Transactions.Assign(value);
            }
        }

        [Association(Name = "Category_Category", Storage = "_Category1", ThisKey = "ParentId", OtherKey = "Id", IsForeignKey = true)]
        public Category Category1
        {
            get
            {
                return this._Category1.Entity;
            }
            set
            {
                Category previousValue = this._Category1.Entity;
                if (((previousValue != value)
                            || (this._Category1.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Category1.Entity = null;
                        previousValue.Categories.Remove(this);
                    }
                    this._Category1.Entity = value;
                    if ((value != null))
                    {
                        value.Categories.Add(this);
                        this._ParentId = value.Id;
                    }
                    else
                    {
                        this._ParentId = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("Category1");
                }
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void attach_Categories(Category entity)
        {
            this.SendPropertyChanging();
            entity.Category1 = this;
        }

        private void detach_Categories(Category entity)
        {
            this.SendPropertyChanging();
            entity.Category1 = null;
        }

        private void attach_MemorizedTransactions(MemorizedTransaction entity)
        {
            this.SendPropertyChanging();
            entity.Category = this;
        }

        private void detach_MemorizedTransactions(MemorizedTransaction entity)
        {
            this.SendPropertyChanging();
            entity.Category = null;
        }

        private void attach_Transactions(Transaction entity)
        {
            this.SendPropertyChanging();
            entity.Category = this;
        }

        private void detach_Transactions(Transaction entity)
        {
            this.SendPropertyChanging();
            entity.Category = null;
        }
    }

    [Table(Name = "dbo.Classes")]
    public partial class Class : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _Id;

        private string _Name;

        private EntitySet<MemorizedTransaction> _MemorizedTransactions;

        private EntitySet<Transaction> _Transactions;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnIdChanging(int value);
        partial void OnIdChanged();
        partial void OnNameChanging(string value);
        partial void OnNameChanged();
        #endregion

        public Class()
        {
            this._MemorizedTransactions = new EntitySet<MemorizedTransaction>(new Action<MemorizedTransaction>(this.attach_MemorizedTransactions), new Action<MemorizedTransaction>(this.detach_MemorizedTransactions));
            this._Transactions = new EntitySet<Transaction>(new Action<Transaction>(this.attach_Transactions), new Action<Transaction>(this.detach_Transactions));
            OnCreated();
        }

        [Column(Storage = "_Id", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int Id
        {
            get
            {
                return this._Id;
            }
            set
            {
                if ((this._Id != value))
                {
                    this.OnIdChanging(value);
                    this.SendPropertyChanging();
                    this._Id = value;
                    this.SendPropertyChanged("Id");
                    this.OnIdChanged();
                }
            }
        }

        [Column(Storage = "_Name", DbType = "NVarChar(50)")]
        public string Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                if ((this._Name != value))
                {
                    this.OnNameChanging(value);
                    this.SendPropertyChanging();
                    this._Name = value;
                    this.SendPropertyChanged("Name");
                    this.OnNameChanged();
                }
            }
        }

        [Association(Name = "Class_MemorizedTransaction", Storage = "_MemorizedTransactions", ThisKey = "Id", OtherKey = "ClassId")]
        public EntitySet<MemorizedTransaction> MemorizedTransactions
        {
            get
            {
                return this._MemorizedTransactions;
            }
            set
            {
                this._MemorizedTransactions.Assign(value);
            }
        }

        [Association(Name = "Class_Transaction", Storage = "_Transactions", ThisKey = "Id", OtherKey = "ClassId")]
        public EntitySet<Transaction> Transactions
        {
            get
            {
                return this._Transactions;
            }
            set
            {
                this._Transactions.Assign(value);
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void attach_MemorizedTransactions(MemorizedTransaction entity)
        {
            this.SendPropertyChanging();
            entity.Class = this;
        }

        private void detach_MemorizedTransactions(MemorizedTransaction entity)
        {
            this.SendPropertyChanging();
            entity.Class = null;
        }

        private void attach_Transactions(Transaction entity)
        {
            this.SendPropertyChanging();
            entity.Class = this;
        }

        private void detach_Transactions(Transaction entity)
        {
            this.SendPropertyChanging();
            entity.Class = null;
        }
    }

    [Table(Name = "dbo.Currencies")]
    public partial class Currency : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _Id;

        private string _Name;

        private string _Description;

        private System.Nullable<decimal> _Rate;

        private EntitySet<Account> _Accounts;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnIdChanging(int value);
        partial void OnIdChanged();
        partial void OnNameChanging(string value);
        partial void OnNameChanged();
        partial void OnDescriptionChanging(string value);
        partial void OnDescriptionChanged();
        partial void OnRateChanging(System.Nullable<decimal> value);
        partial void OnRateChanged();
        #endregion

        public Currency()
        {
            this._Accounts = new EntitySet<Account>(new Action<Account>(this.attach_Accounts), new Action<Account>(this.detach_Accounts));
            OnCreated();
        }

        [Column(Storage = "_Id", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int Id
        {
            get
            {
                return this._Id;
            }
            set
            {
                if ((this._Id != value))
                {
                    this.OnIdChanging(value);
                    this.SendPropertyChanging();
                    this._Id = value;
                    this.SendPropertyChanged("Id");
                    this.OnIdChanged();
                }
            }
        }

        [Column(Storage = "_Name", DbType = "NVarChar(50)")]
        public string Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                if ((this._Name != value))
                {
                    this.OnNameChanging(value);
                    this.SendPropertyChanging();
                    this._Name = value;
                    this.SendPropertyChanged("Name");
                    this.OnNameChanged();
                }
            }
        }

        [Column(Storage = "_Description", DbType = "NVarChar(50)")]
        public string Description
        {
            get
            {
                return this._Description;
            }
            set
            {
                if ((this._Description != value))
                {
                    this.OnDescriptionChanging(value);
                    this.SendPropertyChanging();
                    this._Description = value;
                    this.SendPropertyChanged("Description");
                    this.OnDescriptionChanged();
                }
            }
        }

        [Column(Storage = "_Rate", DbType = "Money")]
        public System.Nullable<decimal> Rate
        {
            get
            {
                return this._Rate;
            }
            set
            {
                if ((this._Rate != value))
                {
                    this.OnRateChanging(value);
                    this.SendPropertyChanging();
                    this._Rate = value;
                    this.SendPropertyChanged("Rate");
                    this.OnRateChanged();
                }
            }
        }

        [Association(Name = "Currency_Account", Storage = "_Accounts", ThisKey = "Id", OtherKey = "CurrencyType")]
        public EntitySet<Account> Accounts
        {
            get
            {
                return this._Accounts;
            }
            set
            {
                this._Accounts.Assign(value);
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void attach_Accounts(Account entity)
        {
            this.SendPropertyChanging();
            entity.Currency = this;
        }

        private void detach_Accounts(Account entity)
        {
            this.SendPropertyChanging();
            entity.Currency = null;
        }
    }

    [Table(Name = "dbo.MemorizedTransactions")]
    public partial class MemorizedTransaction : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _Id;

        private System.Nullable<int> _TransactionType;

        private System.Nullable<int> _AccountId;

        private System.Nullable<int> _CategoryId;

        private System.Nullable<int> _RefId;

        private System.Nullable<int> _ClassId;

        private string _PayMan;

        private System.Nullable<decimal> _Amount;

        private string _Note;

        private System.Nullable<System.DateTime> _CreationOn;

        private System.Nullable<System.DateTime> _ModifiedOn;

        private EntityRef<Account> _Account;

        private EntityRef<Category> _Category;

        private EntityRef<Class> _Class;

        private EntityRef<Ref> _Ref;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnIdChanging(int value);
        partial void OnIdChanged();
        partial void OnTransactionTypeChanging(System.Nullable<int> value);
        partial void OnTransactionTypeChanged();
        partial void OnAccountIdChanging(System.Nullable<int> value);
        partial void OnAccountIdChanged();
        partial void OnCategoryIdChanging(System.Nullable<int> value);
        partial void OnCategoryIdChanged();
        partial void OnRefIdChanging(System.Nullable<int> value);
        partial void OnRefIdChanged();
        partial void OnClassIdChanging(System.Nullable<int> value);
        partial void OnClassIdChanged();
        partial void OnPayManChanging(string value);
        partial void OnPayManChanged();
        partial void OnAmountChanging(System.Nullable<decimal> value);
        partial void OnAmountChanged();
        partial void OnNoteChanging(string value);
        partial void OnNoteChanged();
        partial void OnCreationOnChanging(System.Nullable<System.DateTime> value);
        partial void OnCreationOnChanged();
        partial void OnModifiedOnChanging(System.Nullable<System.DateTime> value);
        partial void OnModifiedOnChanged();
        #endregion

        public MemorizedTransaction()
        {
            this._Account = default(EntityRef<Account>);
            this._Category = default(EntityRef<Category>);
            this._Class = default(EntityRef<Class>);
            this._Ref = default(EntityRef<Ref>);
            OnCreated();
        }

        [Column(Storage = "_Id", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int Id
        {
            get
            {
                return this._Id;
            }
            set
            {
                if ((this._Id != value))
                {
                    this.OnIdChanging(value);
                    this.SendPropertyChanging();
                    this._Id = value;
                    this.SendPropertyChanged("Id");
                    this.OnIdChanged();
                }
            }
        }

        [Column(Storage = "_TransactionType", DbType = "Int")]
        public System.Nullable<int> TransactionType
        {
            get
            {
                return this._TransactionType;
            }
            set
            {
                if ((this._TransactionType != value))
                {
                    this.OnTransactionTypeChanging(value);
                    this.SendPropertyChanging();
                    this._TransactionType = value;
                    this.SendPropertyChanged("TransactionType");
                    this.OnTransactionTypeChanged();
                }
            }
        }

        [Column(Storage = "_AccountId", DbType = "Int")]
        public System.Nullable<int> AccountId
        {
            get
            {
                return this._AccountId;
            }
            set
            {
                if ((this._AccountId != value))
                {
                    if (this._Account.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnAccountIdChanging(value);
                    this.SendPropertyChanging();
                    this._AccountId = value;
                    this.SendPropertyChanged("AccountId");
                    this.OnAccountIdChanged();
                }
            }
        }

        [Column(Storage = "_CategoryId", DbType = "Int")]
        public System.Nullable<int> CategoryId
        {
            get
            {
                return this._CategoryId;
            }
            set
            {
                if ((this._CategoryId != value))
                {
                    if (this._Category.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnCategoryIdChanging(value);
                    this.SendPropertyChanging();
                    this._CategoryId = value;
                    this.SendPropertyChanged("CategoryId");
                    this.OnCategoryIdChanged();
                }
            }
        }

        [Column(Storage = "_RefId", DbType = "Int")]
        public System.Nullable<int> RefId
        {
            get
            {
                return this._RefId;
            }
            set
            {
                if ((this._RefId != value))
                {
                    if (this._Ref.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnRefIdChanging(value);
                    this.SendPropertyChanging();
                    this._RefId = value;
                    this.SendPropertyChanged("RefId");
                    this.OnRefIdChanged();
                }
            }
        }

        [Column(Storage = "_ClassId", DbType = "Int")]
        public System.Nullable<int> ClassId
        {
            get
            {
                return this._ClassId;
            }
            set
            {
                if ((this._ClassId != value))
                {
                    if (this._Class.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnClassIdChanging(value);
                    this.SendPropertyChanging();
                    this._ClassId = value;
                    this.SendPropertyChanged("ClassId");
                    this.OnClassIdChanged();
                }
            }
        }

        [Column(Storage = "_PayMan", DbType = "NVarChar(100)")]
        public string PayMan
        {
            get
            {
                return this._PayMan;
            }
            set
            {
                if ((this._PayMan != value))
                {
                    this.OnPayManChanging(value);
                    this.SendPropertyChanging();
                    this._PayMan = value;
                    this.SendPropertyChanged("PayMan");
                    this.OnPayManChanged();
                }
            }
        }

        [Column(Storage = "_Amount", DbType = "Money")]
        public System.Nullable<decimal> Amount
        {
            get
            {
                return this._Amount;
            }
            set
            {
                if ((this._Amount != value))
                {
                    this.OnAmountChanging(value);
                    this.SendPropertyChanging();
                    this._Amount = value;
                    this.SendPropertyChanged("Amount");
                    this.OnAmountChanged();
                }
            }
        }

        [Column(Storage = "_Note", DbType = "NVarChar(100)")]
        public string Note
        {
            get
            {
                return this._Note;
            }
            set
            {
                if ((this._Note != value))
                {
                    this.OnNoteChanging(value);
                    this.SendPropertyChanging();
                    this._Note = value;
                    this.SendPropertyChanged("Note");
                    this.OnNoteChanged();
                }
            }
        }

        [Column(Storage = "_CreationOn", DbType = "DateTime")]
        public System.Nullable<System.DateTime> CreationOn
        {
            get
            {
                return this._CreationOn;
            }
            set
            {
                if ((this._CreationOn != value))
                {
                    this.OnCreationOnChanging(value);
                    this.SendPropertyChanging();
                    this._CreationOn = value;
                    this.SendPropertyChanged("CreationOn");
                    this.OnCreationOnChanged();
                }
            }
        }

        [Column(Storage = "_ModifiedOn", DbType = "DateTime")]
        public System.Nullable<System.DateTime> ModifiedOn
        {
            get
            {
                return this._ModifiedOn;
            }
            set
            {
                if ((this._ModifiedOn != value))
                {
                    this.OnModifiedOnChanging(value);
                    this.SendPropertyChanging();
                    this._ModifiedOn = value;
                    this.SendPropertyChanged("ModifiedOn");
                    this.OnModifiedOnChanged();
                }
            }
        }

        [Association(Name = "Account_MemorizedTransaction", Storage = "_Account", ThisKey = "AccountId", OtherKey = "AccountId", IsForeignKey = true)]
        public Account Account
        {
            get
            {
                return this._Account.Entity;
            }
            set
            {
                Account previousValue = this._Account.Entity;
                if (((previousValue != value)
                            || (this._Account.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Account.Entity = null;
                        previousValue.MemorizedTransactions.Remove(this);
                    }
                    this._Account.Entity = value;
                    if ((value != null))
                    {
                        value.MemorizedTransactions.Add(this);
                        this._AccountId = value.AccountId;
                    }
                    else
                    {
                        this._AccountId = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("Account");
                }
            }
        }

        [Association(Name = "Category_MemorizedTransaction", Storage = "_Category", ThisKey = "CategoryId", OtherKey = "Id", IsForeignKey = true)]
        public Category Category
        {
            get
            {
                return this._Category.Entity;
            }
            set
            {
                Category previousValue = this._Category.Entity;
                if (((previousValue != value)
                            || (this._Category.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Category.Entity = null;
                        previousValue.MemorizedTransactions.Remove(this);
                    }
                    this._Category.Entity = value;
                    if ((value != null))
                    {
                        value.MemorizedTransactions.Add(this);
                        this._CategoryId = value.Id;
                    }
                    else
                    {
                        this._CategoryId = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("Category");
                }
            }
        }

        [Association(Name = "Class_MemorizedTransaction", Storage = "_Class", ThisKey = "ClassId", OtherKey = "Id", IsForeignKey = true)]
        public Class Class
        {
            get
            {
                return this._Class.Entity;
            }
            set
            {
                Class previousValue = this._Class.Entity;
                if (((previousValue != value)
                            || (this._Class.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Class.Entity = null;
                        previousValue.MemorizedTransactions.Remove(this);
                    }
                    this._Class.Entity = value;
                    if ((value != null))
                    {
                        value.MemorizedTransactions.Add(this);
                        this._ClassId = value.Id;
                    }
                    else
                    {
                        this._ClassId = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("Class");
                }
            }
        }

        [Association(Name = "Ref_MemorizedTransaction", Storage = "_Ref", ThisKey = "RefId", OtherKey = "RefId", IsForeignKey = true)]
        public Ref Ref
        {
            get
            {
                return this._Ref.Entity;
            }
            set
            {
                Ref previousValue = this._Ref.Entity;
                if (((previousValue != value)
                            || (this._Ref.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Ref.Entity = null;
                        previousValue.MemorizedTransactions.Remove(this);
                    }
                    this._Ref.Entity = value;
                    if ((value != null))
                    {
                        value.MemorizedTransactions.Add(this);
                        this._RefId = value.RefId;
                    }
                    else
                    {
                        this._RefId = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("Ref");
                }
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    [Table(Name = "dbo.Refs")]
    public partial class Ref : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _RefId;

        private string _Name;

        private string _Description;

        private EntitySet<MemorizedTransaction> _MemorizedTransactions;

        private EntitySet<Transaction> _Transactions;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnRefIdChanging(int value);
        partial void OnRefIdChanged();
        partial void OnNameChanging(string value);
        partial void OnNameChanged();
        partial void OnDescriptionChanging(string value);
        partial void OnDescriptionChanged();
        #endregion

        public Ref()
        {
            this._MemorizedTransactions = new EntitySet<MemorizedTransaction>(new Action<MemorizedTransaction>(this.attach_MemorizedTransactions), new Action<MemorizedTransaction>(this.detach_MemorizedTransactions));
            this._Transactions = new EntitySet<Transaction>(new Action<Transaction>(this.attach_Transactions), new Action<Transaction>(this.detach_Transactions));
            OnCreated();
        }

        [Column(Storage = "_RefId", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int RefId
        {
            get
            {
                return this._RefId;
            }
            set
            {
                if ((this._RefId != value))
                {
                    this.OnRefIdChanging(value);
                    this.SendPropertyChanging();
                    this._RefId = value;
                    this.SendPropertyChanged("RefId");
                    this.OnRefIdChanged();
                }
            }
        }

        [Column(Storage = "_Name", DbType = "NVarChar(50)")]
        public string Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                if ((this._Name != value))
                {
                    this.OnNameChanging(value);
                    this.SendPropertyChanging();
                    this._Name = value;
                    this.SendPropertyChanged("Name");
                    this.OnNameChanged();
                }
            }
        }

        [Column(Storage = "_Description", DbType = "NVarChar(50)")]
        public string Description
        {
            get
            {
                return this._Description;
            }
            set
            {
                if ((this._Description != value))
                {
                    this.OnDescriptionChanging(value);
                    this.SendPropertyChanging();
                    this._Description = value;
                    this.SendPropertyChanged("Description");
                    this.OnDescriptionChanged();
                }
            }
        }

        [Association(Name = "Ref_MemorizedTransaction", Storage = "_MemorizedTransactions", ThisKey = "RefId", OtherKey = "RefId")]
        public EntitySet<MemorizedTransaction> MemorizedTransactions
        {
            get
            {
                return this._MemorizedTransactions;
            }
            set
            {
                this._MemorizedTransactions.Assign(value);
            }
        }

        [Association(Name = "Ref_Transaction", Storage = "_Transactions", ThisKey = "RefId", OtherKey = "RefId")]
        public EntitySet<Transaction> Transactions
        {
            get
            {
                return this._Transactions;
            }
            set
            {
                this._Transactions.Assign(value);
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void attach_MemorizedTransactions(MemorizedTransaction entity)
        {
            this.SendPropertyChanging();
            entity.Ref = this;
        }

        private void detach_MemorizedTransactions(MemorizedTransaction entity)
        {
            this.SendPropertyChanging();
            entity.Ref = null;
        }

        private void attach_Transactions(Transaction entity)
        {
            this.SendPropertyChanging();
            entity.Ref = this;
        }

        private void detach_Transactions(Transaction entity)
        {
            this.SendPropertyChanging();
            entity.Ref = null;
        }
    }

    [Table(Name = "dbo.Roles")]
    public partial class Role : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _RoleId;

        private string _Name;

        private string _Description;

        private EntitySet<UserInRole> _UserInRoles;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnRoleIdChanging(int value);
        partial void OnRoleIdChanged();
        partial void OnNameChanging(string value);
        partial void OnNameChanged();
        partial void OnDescriptionChanging(string value);
        partial void OnDescriptionChanged();
        #endregion

        public Role()
        {
            this._UserInRoles = new EntitySet<UserInRole>(new Action<UserInRole>(this.attach_UserInRoles), new Action<UserInRole>(this.detach_UserInRoles));
            OnCreated();
        }

        [Column(Storage = "_RoleId", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int RoleId
        {
            get
            {
                return this._RoleId;
            }
            set
            {
                if ((this._RoleId != value))
                {
                    this.OnRoleIdChanging(value);
                    this.SendPropertyChanging();
                    this._RoleId = value;
                    this.SendPropertyChanged("RoleId");
                    this.OnRoleIdChanged();
                }
            }
        }

        [Column(Storage = "_Name", DbType = "NVarChar(50)")]
        public string Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                if ((this._Name != value))
                {
                    this.OnNameChanging(value);
                    this.SendPropertyChanging();
                    this._Name = value;
                    this.SendPropertyChanged("Name");
                    this.OnNameChanged();
                }
            }
        }

        [Column(Storage = "_Description", DbType = "NVarChar(100)")]
        public string Description
        {
            get
            {
                return this._Description;
            }
            set
            {
                if ((this._Description != value))
                {
                    this.OnDescriptionChanging(value);
                    this.SendPropertyChanging();
                    this._Description = value;
                    this.SendPropertyChanged("Description");
                    this.OnDescriptionChanged();
                }
            }
        }

        [Association(Name = "Role_UserInRole", Storage = "_UserInRoles", ThisKey = "RoleId", OtherKey = "RoleId")]
        public EntitySet<UserInRole> UserInRoles
        {
            get
            {
                return this._UserInRoles;
            }
            set
            {
                this._UserInRoles.Assign(value);
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void attach_UserInRoles(UserInRole entity)
        {
            this.SendPropertyChanging();
            entity.Role = this;
        }

        private void detach_UserInRoles(UserInRole entity)
        {
            this.SendPropertyChanging();
            entity.Role = null;
        }
    }

    [Table(Name = "dbo.Settings")]
    public partial class Setting : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _SettingId;

        private string _Key;

        private string _Value;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnSettingIdChanging(int value);
        partial void OnSettingIdChanged();
        partial void OnKeyChanging(string value);
        partial void OnKeyChanged();
        partial void OnValueChanging(string value);
        partial void OnValueChanged();
        #endregion

        public Setting()
        {
            OnCreated();
        }

        [Column(Storage = "_SettingId", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int SettingId
        {
            get
            {
                return this._SettingId;
            }
            set
            {
                if ((this._SettingId != value))
                {
                    this.OnSettingIdChanging(value);
                    this.SendPropertyChanging();
                    this._SettingId = value;
                    this.SendPropertyChanged("SettingId");
                    this.OnSettingIdChanged();
                }
            }
        }

        [Column(Name = "[Key]", Storage = "_Key", DbType = "NVarChar(50)")]
        public string Key
        {
            get
            {
                return this._Key;
            }
            set
            {
                if ((this._Key != value))
                {
                    this.OnKeyChanging(value);
                    this.SendPropertyChanging();
                    this._Key = value;
                    this.SendPropertyChanged("Key");
                    this.OnKeyChanged();
                }
            }
        }

        [Column(Storage = "_Value", DbType = "NVarChar(100)")]
        public string Value
        {
            get
            {
                return this._Value;
            }
            set
            {
                if ((this._Value != value))
                {
                    this.OnValueChanging(value);
                    this.SendPropertyChanging();
                    this._Value = value;
                    this.SendPropertyChanged("Value");
                    this.OnValueChanged();
                }
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    [Table(Name = "dbo.Transactions")]
    public partial class Transaction : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private long _Id;

        private System.Nullable<int> _TransactionType;

        private System.Nullable<int> _AccountId;

        private System.Nullable<int> _CategoryId;

        private System.Nullable<int> _RefId;

        private System.Nullable<int> _ClassId;

        private string _PayMan;

        private System.Nullable<decimal> _Amount;

        private string _Note;

        private System.Nullable<System.DateTime> _CreationOn;

        private System.Nullable<System.DateTime> _ModifiedOn;

        private EntityRef<Account> _Account;

        private EntityRef<Category> _Category;

        private EntityRef<Class> _Class;

        private EntityRef<Ref> _Ref;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnIdChanging(long value);
        partial void OnIdChanged();
        partial void OnTransactionTypeChanging(System.Nullable<int> value);
        partial void OnTransactionTypeChanged();
        partial void OnAccountIdChanging(System.Nullable<int> value);
        partial void OnAccountIdChanged();
        partial void OnCategoryIdChanging(System.Nullable<int> value);
        partial void OnCategoryIdChanged();
        partial void OnRefIdChanging(System.Nullable<int> value);
        partial void OnRefIdChanged();
        partial void OnClassIdChanging(System.Nullable<int> value);
        partial void OnClassIdChanged();
        partial void OnPayManChanging(string value);
        partial void OnPayManChanged();
        partial void OnAmountChanging(System.Nullable<decimal> value);
        partial void OnAmountChanged();
        partial void OnNoteChanging(string value);
        partial void OnNoteChanged();
        partial void OnCreationOnChanging(System.Nullable<System.DateTime> value);
        partial void OnCreationOnChanged();
        partial void OnModifiedOnChanging(System.Nullable<System.DateTime> value);
        partial void OnModifiedOnChanged();
        #endregion

        public Transaction()
        {
            this._Account = default(EntityRef<Account>);
            this._Category = default(EntityRef<Category>);
            this._Class = default(EntityRef<Class>);
            this._Ref = default(EntityRef<Ref>);
            OnCreated();
        }

        [Column(Storage = "_Id", AutoSync = AutoSync.OnInsert, DbType = "BigInt NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public long Id
        {
            get
            {
                return this._Id;
            }
            set
            {
                if ((this._Id != value))
                {
                    this.OnIdChanging(value);
                    this.SendPropertyChanging();
                    this._Id = value;
                    this.SendPropertyChanged("Id");
                    this.OnIdChanged();
                }
            }
        }

        [Column(Storage = "_TransactionType", DbType = "Int")]
        public System.Nullable<int> TransactionType
        {
            get
            {
                return this._TransactionType;
            }
            set
            {
                if ((this._TransactionType != value))
                {
                    this.OnTransactionTypeChanging(value);
                    this.SendPropertyChanging();
                    this._TransactionType = value;
                    this.SendPropertyChanged("TransactionType");
                    this.OnTransactionTypeChanged();
                }
            }
        }

        [Column(Storage = "_AccountId", DbType = "Int")]
        public System.Nullable<int> AccountId
        {
            get
            {
                return this._AccountId;
            }
            set
            {
                if ((this._AccountId != value))
                {
                    if (this._Account.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnAccountIdChanging(value);
                    this.SendPropertyChanging();
                    this._AccountId = value;
                    this.SendPropertyChanged("AccountId");
                    this.OnAccountIdChanged();
                }
            }
        }

        [Column(Storage = "_CategoryId", DbType = "Int")]
        public System.Nullable<int> CategoryId
        {
            get
            {
                return this._CategoryId;
            }
            set
            {
                if ((this._CategoryId != value))
                {
                    if (this._Category.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnCategoryIdChanging(value);
                    this.SendPropertyChanging();
                    this._CategoryId = value;
                    this.SendPropertyChanged("CategoryId");
                    this.OnCategoryIdChanged();
                }
            }
        }

        [Column(Storage = "_RefId", DbType = "Int")]
        public System.Nullable<int> RefId
        {
            get
            {
                return this._RefId;
            }
            set
            {
                if ((this._RefId != value))
                {
                    if (this._Ref.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnRefIdChanging(value);
                    this.SendPropertyChanging();
                    this._RefId = value;
                    this.SendPropertyChanged("RefId");
                    this.OnRefIdChanged();
                }
            }
        }

        [Column(Storage = "_ClassId", DbType = "Int")]
        public System.Nullable<int> ClassId
        {
            get
            {
                return this._ClassId;
            }
            set
            {
                if ((this._ClassId != value))
                {
                    if (this._Class.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnClassIdChanging(value);
                    this.SendPropertyChanging();
                    this._ClassId = value;
                    this.SendPropertyChanged("ClassId");
                    this.OnClassIdChanged();
                }
            }
        }

        [Column(Storage = "_PayMan", DbType = "NVarChar(100)")]
        public string PayMan
        {
            get
            {
                return this._PayMan;
            }
            set
            {
                if ((this._PayMan != value))
                {
                    this.OnPayManChanging(value);
                    this.SendPropertyChanging();
                    this._PayMan = value;
                    this.SendPropertyChanged("PayMan");
                    this.OnPayManChanged();
                }
            }
        }

        [Column(Storage = "_Amount", DbType = "Money")]
        public System.Nullable<decimal> Amount
        {
            get
            {
                return this._Amount;
            }
            set
            {
                if ((this._Amount != value))
                {
                    this.OnAmountChanging(value);
                    this.SendPropertyChanging();
                    this._Amount = value;
                    this.SendPropertyChanged("Amount");
                    this.OnAmountChanged();
                }
            }
        }

        [Column(Storage = "_Note", DbType = "NVarChar(100)")]
        public string Note
        {
            get
            {
                return this._Note;
            }
            set
            {
                if ((this._Note != value))
                {
                    this.OnNoteChanging(value);
                    this.SendPropertyChanging();
                    this._Note = value;
                    this.SendPropertyChanged("Note");
                    this.OnNoteChanged();
                }
            }
        }

        [Column(Storage = "_CreationOn", DbType = "DateTime")]
        public System.Nullable<System.DateTime> CreationOn
        {
            get
            {
                return this._CreationOn;
            }
            set
            {
                if ((this._CreationOn != value))
                {
                    this.OnCreationOnChanging(value);
                    this.SendPropertyChanging();
                    this._CreationOn = value;
                    this.SendPropertyChanged("CreationOn");
                    this.OnCreationOnChanged();
                }
            }
        }

        [Column(Storage = "_ModifiedOn", DbType = "DateTime")]
        public System.Nullable<System.DateTime> ModifiedOn
        {
            get
            {
                return this._ModifiedOn;
            }
            set
            {
                if ((this._ModifiedOn != value))
                {
                    this.OnModifiedOnChanging(value);
                    this.SendPropertyChanging();
                    this._ModifiedOn = value;
                    this.SendPropertyChanged("ModifiedOn");
                    this.OnModifiedOnChanged();
                }
            }
        }

        [Association(Name = "Account_Transaction", Storage = "_Account", ThisKey = "AccountId", OtherKey = "AccountId", IsForeignKey = true)]
        public Account Account
        {
            get
            {
                return this._Account.Entity;
            }
            set
            {
                Account previousValue = this._Account.Entity;
                if (((previousValue != value)
                            || (this._Account.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Account.Entity = null;
                        previousValue.Transactions.Remove(this);
                    }
                    this._Account.Entity = value;
                    if ((value != null))
                    {
                        value.Transactions.Add(this);
                        this._AccountId = value.AccountId;
                    }
                    else
                    {
                        this._AccountId = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("Account");
                }
            }
        }

        [Association(Name = "Category_Transaction", Storage = "_Category", ThisKey = "CategoryId", OtherKey = "Id", IsForeignKey = true)]
        public Category Category
        {
            get
            {
                return this._Category.Entity;
            }
            set
            {
                Category previousValue = this._Category.Entity;
                if (((previousValue != value)
                            || (this._Category.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Category.Entity = null;
                        previousValue.Transactions.Remove(this);
                    }
                    this._Category.Entity = value;
                    if ((value != null))
                    {
                        value.Transactions.Add(this);
                        this._CategoryId = value.Id;
                    }
                    else
                    {
                        this._CategoryId = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("Category");
                }
            }
        }

        [Association(Name = "Class_Transaction", Storage = "_Class", ThisKey = "ClassId", OtherKey = "Id", IsForeignKey = true)]
        public Class Class
        {
            get
            {
                return this._Class.Entity;
            }
            set
            {
                Class previousValue = this._Class.Entity;
                if (((previousValue != value)
                            || (this._Class.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Class.Entity = null;
                        previousValue.Transactions.Remove(this);
                    }
                    this._Class.Entity = value;
                    if ((value != null))
                    {
                        value.Transactions.Add(this);
                        this._ClassId = value.Id;
                    }
                    else
                    {
                        this._ClassId = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("Class");
                }
            }
        }

        [Association(Name = "Ref_Transaction", Storage = "_Ref", ThisKey = "RefId", OtherKey = "RefId", IsForeignKey = true)]
        public Ref Ref
        {
            get
            {
                return this._Ref.Entity;
            }
            set
            {
                Ref previousValue = this._Ref.Entity;
                if (((previousValue != value)
                            || (this._Ref.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Ref.Entity = null;
                        previousValue.Transactions.Remove(this);
                    }
                    this._Ref.Entity = value;
                    if ((value != null))
                    {
                        value.Transactions.Add(this);
                        this._RefId = value.RefId;
                    }
                    else
                    {
                        this._RefId = default(Nullable<int>);
                    }
                    this.SendPropertyChanged("Ref");
                }
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    [Table(Name = "dbo.UserInRoles")]
    public partial class UserInRole : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _UserId;

        private int _RoleId;

        private EntityRef<Role> _Role;

        private EntityRef<User> _User;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnUserIdChanging(int value);
        partial void OnUserIdChanged();
        partial void OnRoleIdChanging(int value);
        partial void OnRoleIdChanged();
        #endregion

        public UserInRole()
        {
            this._Role = default(EntityRef<Role>);
            this._User = default(EntityRef<User>);
            OnCreated();
        }

        [Column(Storage = "_UserId", DbType = "Int NOT NULL", IsPrimaryKey = true)]
        public int UserId
        {
            get
            {
                return this._UserId;
            }
            set
            {
                if ((this._UserId != value))
                {
                    if (this._User.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnUserIdChanging(value);
                    this.SendPropertyChanging();
                    this._UserId = value;
                    this.SendPropertyChanged("UserId");
                    this.OnUserIdChanged();
                }
            }
        }

        [Column(Storage = "_RoleId", DbType = "Int NOT NULL", IsPrimaryKey = true)]
        public int RoleId
        {
            get
            {
                return this._RoleId;
            }
            set
            {
                if ((this._RoleId != value))
                {
                    if (this._Role.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnRoleIdChanging(value);
                    this.SendPropertyChanging();
                    this._RoleId = value;
                    this.SendPropertyChanged("RoleId");
                    this.OnRoleIdChanged();
                }
            }
        }

        [Association(Name = "Role_UserInRole", Storage = "_Role", ThisKey = "RoleId", OtherKey = "RoleId", IsForeignKey = true)]
        public Role Role
        {
            get
            {
                return this._Role.Entity;
            }
            set
            {
                Role previousValue = this._Role.Entity;
                if (((previousValue != value)
                            || (this._Role.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Role.Entity = null;
                        previousValue.UserInRoles.Remove(this);
                    }
                    this._Role.Entity = value;
                    if ((value != null))
                    {
                        value.UserInRoles.Add(this);
                        this._RoleId = value.RoleId;
                    }
                    else
                    {
                        this._RoleId = default(int);
                    }
                    this.SendPropertyChanged("Role");
                }
            }
        }

        [Association(Name = "User_UserInRole", Storage = "_User", ThisKey = "UserId", OtherKey = "UserId", IsForeignKey = true)]
        public User User
        {
            get
            {
                return this._User.Entity;
            }
            set
            {
                User previousValue = this._User.Entity;
                if (((previousValue != value)
                            || (this._User.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._User.Entity = null;
                        previousValue.UserInRoles.Remove(this);
                    }
                    this._User.Entity = value;
                    if ((value != null))
                    {
                        value.UserInRoles.Add(this);
                        this._UserId = value.UserId;
                    }
                    else
                    {
                        this._UserId = default(int);
                    }
                    this.SendPropertyChanged("User");
                }
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
